<template>
	<view class="goods-collection">
		<view v-if="!isNull" class="list">
			<view class="item" v-for="item in goodsList" :key="item.id" @tap="toGoodsInfo(item.id)">
				<image :src="item.pic" mode=""></image>

				<view class="info-holder">
					<view class="name">
						{{item.name}}
					</view>
					<view class="price-holder">
						<text>收藏</text>
						<text class="price">￥{{item.price}}</text>
					</view>
				</view>
			</view>
		</view>

		<view v-else class="isNull">
			商品收藏列表为空
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				goodsList: [],
				isNull: true,
			};
		},
		methods: {
			toGoodsInfo(id) {
				uni.navigateTo({
					url: `/pages/goodsInfo/goodsInfo?goodsId=${id}`,
				})
			}
		},
		onShow() {
			this.goodsList = uni.getStorageSync('goodsCollect');
			if (uni.getStorageSync('goodsCollect') && this.goodsList.length > 0) {
				this.isNull = false;
			}
			console.log(this.goodsList);
		}
	}
</script>

<style lang="scss" scoped>
	.goods-collection {
		.list {
			box-sizing: border-box;
			padding: 40px 30rpx;
			width: 100%;

			.item {
				display: flex;
				justify-content: space-between;
				align-items: center;
				box-sizing: border-box;
				padding: 30rpx;
				margin-bottom: 40rpx;
				width: 100%;
				height: 220rpx;
				background-color: #fff;
				border-radius: 10rpx;

				image {
					width: 124rpx;
					height: 160rpx;
					border-radius: 20rpx;
				}

				.info-holder {
					display: flex;
					flex-wrap: wrap;
					width: 464rpx;
					height: 150rpx;
					font-size: 24rpx;
					color: #494949;
					line-height: 40rpx;


					.name {
						width: 100%;
					}

					.price-holder {
						display: flex;
						justify-content: space-between;
						width: 100%;

						.price {
							font-size: 32rpx;
							font-weight: 600;
						}
					}
				}
			}
		}
	}
</style>
